//
//  HYBaseViewController.m
//  HYChatProject
//
//  Created by Jagtu on 2018/3/4.
//  Copyright © 2018年 erpapa. All rights reserved.
//

#import "HYBaseViewController.h"
#import "HYUtils.h"
#import "YLZYHErrorView.h"

@interface HYBaseViewController ()

@property(nonatomic,strong)YLZYHErrorView *errorView;

@end

@implementation HYBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = APP_ViewBg_COLOR;
    
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_left"] style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    
    [self initData];
    [self createView];
    [self layoutSubviews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initData
{
}

-(void)createView
{
}

-(void)layoutSubviews
{
    
}

-(void)back:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)dealloc
{
    
}


-(void)addErrorViewWithMsg:(NSString *)message
{
    [self.view addSubview:self.errorView];
    [self.view bringSubviewToFront:self.errorView];
    self.errorView.errorLabel.text = message;
    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)removeErrorView
{
    [self.errorView removeFromSuperview];
    self.errorView = nil;
    self.view.backgroundColor = APP_ViewBg_COLOR;
}

-(YLZYHErrorView *)errorView
{
    if (!_errorView) {
        
        CGFloat height = 172 * WIDTHRATE;
        _errorView = [[YLZYHErrorView alloc]initWithFrame:CGRectMake(0, (self.view.frame.size.height-(height+100))/2.0, VERTICAL_SCREEN_WIDTH, height + 100)];
        
        if ([self respondsToSelector:@selector(reloadActionWhenError)]) {
            YHWeakifySelf;
            [_errorView setReloadBlock:^{
                [yh_weak_self performSelector:@selector(reloadActionWhenError)];
            }];
        }
    }
    return _errorView;
}

-(void)reloadActionWhenError
{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
